package com.guge.sports.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guge.sports.entity.Dto.Option;
import com.guge.sports.entity.Dto.StDeptDto;
import com.guge.sports.entity.StDept;
import com.guge.sports.entity.StSchool;
import com.guge.sports.mapper.StDeptMapper;
import com.guge.sports.mapper.StSchoolMapper;
import com.guge.sports.service.StDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guge.sports.toolPackage.base.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-09-14
 */
@Service
@Transactional
public class StDeptServiceImpl extends BaseService<StDept> implements StDeptService {

    @Autowired
    private StDeptMapper stDeptMapper;

    @Autowired
    private StSchoolMapper stSchoolMapper;

    /**
     * 获取 院系列表
     * @return
     */
    @Override
    public List<Option> getDeptNameAndDidList() {
        return stDeptMapper.getDeptNameAndDidList();
    }

    @Override
    public List<StDeptDto> selectDeptList() {

        return stDeptMapper.selectDeptList();
    }

    @Override
    public Page<StDeptDto> StDeptDtoList(Page<StDeptDto> page) {
        return stDeptMapper.StDeptDtoList(page);
    }

    @Override
    public void StDeptDtoAdd(StDeptDto stDeptDto) {
        Date date = new Date();
        StDept stDept = new StDept();
        stDept.setCreateTime(date);
        stDept.setUpdateTime(date);
        stDept.setSchoolId(stDeptDto.getSchoolId());
        stDept.setDeptName(stDeptDto.getDeptName());
        stDept.setSort(stDeptDto.getSort());
        stDept.setRemarks(stDeptDto.getRemarks());
        stDept.setState(stDeptDto.getState());
        stDeptMapper.insert(stDept);
    }

    @Override
    public void DeleteById(Long id) {
        StDept stDept = new StDept();
        stDept.setDid(id);
        stDept.setIsdelete(1);
        stDeptMapper.updateById(stDept);
    }

    @Override
    public StDeptDto SelectById(Long id) {
        return stDeptMapper.SelectById(id);

    }

    @Override
    public void StDeptUpdateByid(StDept stDeptDto) {
        stDeptDto.setUpdateTime(new Date());
        stDeptMapper.updateById(stDeptDto);
    }
}
